﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Compression;
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;

namespace TestZip
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            label3.Visible = false;
        }



        private void button1_Click(object sender, EventArgs e)
        {
            string str = "";
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                label3.Visible = true;
                this.Enabled = false;
                var files = Directory.GetFiles(textBox1.Text);
                string fileName = textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1);
                if (radioButton1.Checked == true)
                {
                    str = DateTime.Now.Date.ToShortDateString() + "-" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString();

                    ZipHelper.ZipFiles(textBox2.Text + "\\" + fileName + "-" + str + ".zip", files, System.IO.Packaging.CompressionOption.Normal);
                }
                else
                {
                    if (File.Exists(textBox2.Text + "\\" + fileName + ".zip"))
                    {
                        MessageBox.Show("Destination path already contains file with same name");
                        this.Enabled = true;
                        label3.Visible = false;
                    }
                    else
                        ZipHelper.ZipFiles(textBox2.Text + "\\" + fileName + ".zip", files, System.IO.Packaging.CompressionOption.Normal);
                }
                this.Enabled = true;
                label3.Visible = false;
                MessageBox.Show("Compression completed successfully");
            }
            else
                MessageBox.Show("Please enter source folder and destination folder");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult result = folderBrowserDialog2.ShowDialog();
            if (result == DialogResult.OK)
            {
                textBox2.Text = folderBrowserDialog2.SelectedPath;

            }
        }




    }
}
